package com.ruoyi.web.contrller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Drugstore;
import com.ruoyi.web.service.IDrugstoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 药品库存Controller
 */
@RestController
@RequestMapping("/warehouse/drugstore")
public class DrugstoreController  extends BaseController {
    @Autowired
    private IDrugstoreService drugstoreService;

    /**
     * 查询药品库存列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drugstore:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drugstore drugstore)
    {
        startPage();
        List<Drugstore> list = drugstoreService.selectDrugstoreList(drugstore);
        return getDataTable(list);
    }

    /**
     * 获取药品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drugstore:query')")
    @GetMapping(value = "/{rugstoreId}")
    public AjaxResult getInfo(@PathVariable("rugstoreId") Long rugstoreId)
    {
        return success(drugstoreService.selectDrugstoreByRugstoreId(rugstoreId));
    }
    /**
     * 修改药品库存
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drugstore:edit')")
    @Log(title = "药品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drugstore drugstore)
    {
        return toAjax(drugstoreService.updateDrugstore(drugstore));
    }

    /**
     * 删除药品库存
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drugstore:remove')")
    @Log(title = "药品库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rugstoreIds}")
    public AjaxResult remove(@PathVariable Long rugstoreIds)
    {
        return toAjax(drugstoreService.deleteDrugstoreByRugstoreId(rugstoreIds));
    }

    /**
     * 入库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drugstore:add')")
    @Log(title = "药品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drugstore drugstore)
    {
        return toAjax(drugstoreService.insertDrugstore(drugstore));
    }
}
